package com.demo.controllers;

import com.demo.util.excel.ExcelData;
import com.demo.util.excel.ExportExcelUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

/**
 * @Description:
 * @author: fanfan
 * @date: 2018/8/15 15:34
 */
@RestController
@RequestMapping("/excel")
public class Excel {

    @RequestMapping("/test")
    public void test(HttpServletResponse response) throws Exception {
        List<String> num1=new LinkedList<>();
        num1.add("1");
        num1.add("2");
        ExcelData data=new ExcelData();
        List<String> title=new LinkedList<>();
        title.add("第一列");
        title.add("第二列");
        data.setTitles(title);

        data.setName("test");

        List<List<Object>> rows = new ArrayList();
        for (String i : num1){
            List<Object> row = new ArrayList();
            row.add(i);
        }
        data.setRows(rows);

        ExportExcelUtils.exportExcel(response,"test.xls",data);

    }
}
